package com.example.demo.controller;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.example.demo.common.Result;
import com.example.demo.entity.ExpectedPosition;
import com.example.demo.service.ExpectedPositionService;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;


/**
 * 期望职位表(ExpectedPosition)表控制层
 *
 * @author makejava
 * @since 2023-12-19 08:15:51
 */
@RestController
@RequestMapping("expectedPosition")
public class ExpectedPositionController {
    /**
     * 服务对象
     */
    @Autowired
    private ExpectedPositionService expectedPositionService;


    /**
     * 新增/编辑数据
     *
     * @param expectedPosition 实体对象
     * @return 新增结果
     */
    @PostMapping("doAdd")
    public Result daAdd(@RequestBody ExpectedPosition expectedPosition) {
        try {
            if (expectedPosition.getId()==null){
                expectedPositionService.save(expectedPosition);
                return Result.success("添加成功");
            }else {
                UpdateWrapper<ExpectedPosition> wrapper=new UpdateWrapper<>();
                wrapper.eq("id",expectedPosition.getId());
                expectedPositionService.update(expectedPosition,wrapper);
                return Result.success("编辑成功");
            }
        }catch (Exception e){
            return Result.error("参数错误");
        }
    }


    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除结果
     */
    @DeleteMapping("delete")
    public Result delete(Integer id) {
        try {
            QueryWrapper<ExpectedPosition> wrapper=new QueryWrapper<>();
            wrapper.eq("id",id);
            expectedPositionService.remove(wrapper);
            return Result.success("删除成功");
        }catch (Exception e){
            return Result.error("参数错误");
        }
    }
}

